/**
 * @name        template.ts
 * @author      shenyc
 * @date        2020-05-06 - ?
 * @copyright   Copy right (c) shenyc (shenyczz@163.com).
 *              All rights reserved.
 *
 ******************************************************************************/
// {{@@@}}
"use strict"
// ----------------------------------------------------------------------------
import type {
    InputOption,
    InputPluginOption,
    OutputOptions,
    OutputPluginOption,
    RollupOptions, //
    GlobalsOption
} from "rollup"

import { BundleFormat } from "./BundleFormat"
import { getPreferenceOption } from "./PreferenceOption"
import { getOutputCommon } from "./internal"

/**
 * 多模块输入
 * @param inputs
 */
function multipleChunkInputs(inputs: string[] | Record<string, string>) {
    return inputs as InputOption
}

/**
 * 多模块输出
 * @param formatting
 * @param minify
 * @returns
 */
function multipleChunkOutputs(formatting: BundleFormat, minify?: OutputPluginOption) {
    //
    const outputCommon = getOutputCommon()
    const { outDir, globals, banner, footer } = getPreferenceOption()

    const _output: OutputOptions = {
        dir: `${outDir}/${formatting.toString().toLowerCase()}`,
        format: `${formatting}`,
        name: `${formatting}.namespace`,
        globals: globals,
        banner: banner,
        footer: footer,
        ...outputCommon
    }

    if (minify) {
        _output.plugins = minify // 压缩代码
    }

    return _output
}

export { multipleChunkInputs, multipleChunkOutputs }
// ----------------------------------------------------------------------------
// {{@@@}}
